﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;

namespace Server_NhaSach.DataAccess.LogicLayer
{
    [Serializable]
    public class CTKHDatHangDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertCTKHDatHang(CTKHDatHangDTO CTKHDatHang)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[8];
            par[0] = new SqlParameter("@MAMH", CTKHDatHang.MaMH);
            par[1] = new SqlParameter("@MaKHDH", CTKHDatHang.MaKHDH);
            par[2] = new SqlParameter("@SoLuong", CTKHDatHang.Soluong);
            par[3] = new SqlParameter("@DVT", CTKHDatHang.Dvt);
            par[4] = new SqlParameter("@DonGia", CTKHDatHang.Dongia);
            par[5] = new SqlParameter("@ChietKhau", CTKHDatHang.Chietkhau);
            par[6] = new SqlParameter("@ThanhTien", CTKHDatHang.Thanhtien);
            par[7] = new SqlParameter("@DaGiao", CTKHDatHang.Dagiao);
            try
            {
                helper.InsertQuery("sp_Insert_CTKHDatHang", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateCTKHDatHang(CTKHDatHangDTO CTKHDatHang)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[8];
            par[0] = new SqlParameter("@MAMH", CTKHDatHang.MaMH);
            par[1] = new SqlParameter("@MaKHDH", CTKHDatHang.MaKHDH);
            par[2] = new SqlParameter("@SoLuong", CTKHDatHang.Soluong);
            par[3] = new SqlParameter("@DVT", CTKHDatHang.Dvt);
            par[4] = new SqlParameter("@DonGia", CTKHDatHang.Dongia);
            par[5] = new SqlParameter("@ChietKhau", CTKHDatHang.Chietkhau);
            par[6] = new SqlParameter("@ThanhTien", CTKHDatHang.Thanhtien);
            par[7] = new SqlParameter("@DaGiao", CTKHDatHang.Dagiao);
            try
            {
                helper.UpdateQuery("sp_Update_CTKHDatHang", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteCTKHDatHang(string maMH, string maKHDH)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[2];
            par[0] = new SqlParameter("@maMH", maMH);
            par[1] = new SqlParameter("@maKHDH", maKHDH);
            try
            {
                helper.DeleteQuery("sp_Delete_CTKHDatHang", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_CTKHDatHang()
        {
            helper = new Helper();
            DataSet ds = helper.SelectQuery("sp_LayDS_CTKHDatHang");
            return ds;
        }
        #endregion
    }
}